{extend name="iframe" /}

{block name="body"}
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <form action="{:request()->url()}" method="post" class="xn_ajax2" data-type="open">
        <blockquote class="layui-elem-quote layui-quote-nm">
            <div class="layui-form-item">
                <label class="layui-form-label">文章类型</label>
                <div class="layui-input-block" id="part">
                  <input type="radio" name="part" value="组合" title="组合" checked=""><div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div>男</div></div>
                  <input type="radio" name="part" value="伪原创" title="伪原创"><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>女</div></div>
                  <input type="radio" name="part" value="原创" title="原创"><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>女</div></div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">筛选</label>
                <div class="layui-input-inline">
                    <select name="parent_typeid" lay-filter="parent_typeid" id="parent_typeid">
                        <option value="0">请选择</option>
                        {foreach name="parent_typelist" item="vo"}
                        <option value="{$vo.id}" {if condition="$data.parent_typeid eq $vo.id"}selected{/if} >{$vo.title}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="layui-input-inline">
                    <select name="typeid" id="typeid">
                        <option value="0">请选择</option>
                        {foreach name="typelist" item="vo"}
                        <option value="{$vo.id}" {if condition="$data.typeid eq $vo.id"}selected{/if} >{$vo.title}</option>
                        {/foreach}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">推送目标</label>
                <div class="layui-input-block">
                    <div class="layui-input-inline">
                        <select name="webid" lay-filter="webid" id="webid">
                            <option value="0">选择站点</option>
                            {foreach name="weblist" item="vo"}
                            <option value="{$vo.id}" {if condition="$data.webid eq $vo.id"}selected{/if} >{$vo.title}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select name="catid" id="catid">
                            <option value="0">选择栏目</option>
                        </select>
                    </div>
                </div>
            </div>
            
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" onclick="getNum()">获取可推送数量</button>
                </div>
            </div>
        </blockquote>
        
        <div class="layui-form-item">
            <label class="layui-form-label">推送数量</label>
            <div class="layui-input-block layui-form-select">
                <input type="text" name="num" id="num" class="layui-input" value="" >
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" onclick="push()">推送</button>
            </div>
        </div>
        
    </form>
</div>
{/block}
{block name="js"}
<script>
    var form = layui.form;
    form.on('select(parent_typeid)', function(res) { 
        $("#typeid").empty();
        if(res.value != 0){
            $.get("{:url('admin/DataType/getSonType')}?pid="+res.value,function(result){
                if(result.status){
                    $("#typeid").append(new Option('请选择',0));
                    $.each(result.data,function(index,item){
                        $("#typeid").append(new Option(item.title,item.id));
                    });
                    form.render("select");
                }
            });
        }else{
            $("#typeid").append(new Option('请选择',0));
            form.render("select");
        }
    })

    function getNum(){
        var part = $('#part input[name="part"]:checked').val();
        var webid = $('#webid').val();
        var parent_typeid = $('#parent_typeid').val();
        var typeid = $('#typeid').val();
        $.get("{:url('articleGetNum')}",{part:part,webid:webid,parent_typeid:parent_typeid,typeid:typeid},function(res){
            layer.msg(res.msg,{time:1500});
            if(res.status){
                $('#num').val(res.data);
            }
        });
    }

    function push(count=0){
        var part = $('#part input[name="part"]:checked').val();
        var webid = $('#webid').val();
        var catid = $('#catid').val();
        var parent_typeid = $('#parent_typeid').val();
        var typeid = $('#typeid').val();
        var num = $('#num').val();
        if(count==0){
            layer.msg('开始执行', {icon: 1,time: 0});
        }
        $.get("{:url('articlePush')}",{part:part,webid:webid,catid:catid,parent_typeid:parent_typeid,typeid:typeid,num:num,count:count},function(res){
            if(res.status){
                layer.msg(res.msg, {icon: 1,time: 0}); 
                push(res.data.count);
            }else{
                layer.msg(res.msg, {icon: 1,time: 2000},function(){
                    location.reload();
                });
            }
        });
    }

    form.on('select(webid)', function(res) { 
        $("#catid").empty();
        if(res.value != 0){
            $.get("{:url('admin/ajax/getSiteArticleCategoryList')}",{webid:res.value},function(result){
                if(result.status){
                    $("#catid").append(new Option('请选择',0));
                    $.each(result.data,function(index,item){
                        $("#catid").append(new Option(item.catname,item.catid));
                        if(item.children != null){
                            $.each(item.children,function(i,v){
                                $("#catid").append(new Option('├ '+v.catname,v.catid));
                            });
                        }
                    });
                    form.render("select");
                }
            });
        }else{
            $("#catid").append(new Option('请选择',0));
            form.render("select");
        }
    })


</script>
{/block}